<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>async and await</h1>
	</body>

	<script type="text/javascript">
		async function asycnFunction() {
			return 'hello';
		}

		let result = asycnFunction();
		console.log(result) // Promise object
		// 简写形式
		result.then(console.log)


		function reload() {
			return new Promise((resolve, reject) => {
				setTimeout(function() {
					console.log('loading is over');
					resolve('success');
				}, 2000)
			});
		}

		// await 只在异步函数里面才起作用
		async function asyncWait() {
			// 编写一个异步，执行等待
			let result = await reload();
			return result;
		}
		asyncWait().then(res => {
			console.log(res)
		})

		console.log('all is over')
	</script>

</html>
